package com.tangl.demo.service.impl;

import com.tangl.demo.Document.LogDocument;
import com.tangl.demo.repository.mongo.LogTomongoRepository;
import com.tangl.demo.service.logToMongoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: TangLiang
 * @date: 2020/8/4 9:11
 * @since: 1.0
 */
@Service
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public class logToMongoServiceImpl implements logToMongoService {
    @Autowired
    private LogTomongoRepository logTomongoRepository;

    @Override
    public List<LogDocument> list(String id) {
        return logTomongoRepository.findAll();
    }

    @Override
    public int create(LogDocument logDocument) {
        logTomongoRepository.save(logDocument);
        return 1;
    }

    @Override
    public int delete(List<String> ids) {
        List<LogDocument> deleteList = new ArrayList<>();
        for
        (String id : ids) {
            LogDocument logDocument = new LogDocument();
            logDocument.setId(id);
            deleteList.add(logDocument);
        }
        logTomongoRepository.deleteAll(deleteList);
        return ids.size();
    }

}
